package com.afkt.project.ui.slice;


import com.afkt.project.base.app.BaseActivity;
import com.afkt.project.model.item.ButtonValue;
import com.afkt.project.ui.adapter.ButtonAdapter;
import com.afkt.project.util.LogUtils;
import com.ohos.afkt.ResourceTable;
import com.dev.DevUtils;
import com.dev.utils.app.ResourceUtils;
import com.dev.utils.app.toast.ToastTintUtils;
import ohos.aafwk.content.Intent;
import ohos.agp.components.*;
import ohos.agp.components.element.Element;
import ohos.agp.utils.Color;


import java.util.ArrayList;
import java.util.List;

public class ToastTintSlice extends BaseActivity {

    private static final String TAG = ToastTintSlice.class.getSimpleName();


    private DirectionalLayout bar_Layout;
    private DirectionalLayout bar;
    private Image select_retuen;
    @Override
    protected void onStart(Intent intent) {
        super.onStart(intent);
        bar_Layout = (DirectionalLayout) findComponentById(ResourceTable.Id_base_view_barLayout);
        bar = (DirectionalLayout) LayoutScatter.getInstance(this).parse(ResourceTable.Layout_sheet_dialog_bar, null, false);
        Text text = (Text) bar.findComponentById(ResourceTable.Id_titleText);
        select_retuen = (Image) bar.findComponentById(ResourceTable.Id_sheet_dialog_return);
        text.setText("ToastTint(着色美化Toast)");
        bar_Layout.addComponent(bar);

        ListContainer vidBvrRecy = (ListContainer) findComponentById(ResourceTable.Id_vid_bvr_recy);
        ButtonAdapter buttonAdapter = new ButtonAdapter(getToastButtonValues(), getContext());
        vidBvrRecy.setItemProvider(buttonAdapter);

        LogUtils.error(TAG, " color Value = " + Color.getIntColor("#388E3C") + " red " + Color.RED.getValue());
        DevUtils.setContext(this);

        ToastTintUtils.setGravity(0 , 0, 500);
        vidBvrRecy.setItemClickedListener((listContainer, component, i, l) -> {

            LogUtils.error(TAG, "i = " + i);

           ButtonValue buttonValue = (ButtonValue) listContainer.getItemProvider().getItem(i);

           switch (buttonValue.type) {
               case ButtonValue.BTN_TOAST_TINT_SUCCESS:
                   LogUtils.error(TAG, "success");
                   ToastTintUtils.success("Success Style Toast");
                   break;
               case ButtonValue.BTN_TOAST_TINT_ERROR:
                   LogUtils.error(TAG, "error");
                   ToastTintUtils.error("Error Style Toast");
                   break;
               case ButtonValue.BTN_TOAST_TINT_INFO:
                   LogUtils.error(TAG, "info");
                   ToastTintUtils.info("Info Style Toast");
                   break;
               case ButtonValue.BTN_TOAST_TINT_NORMAL:
                   LogUtils.error(TAG, "normal");
                   ToastTintUtils.normal("Normal Style Toast");
                   break;
               case ButtonValue.BTN_TOAST_TINT_WARNING:
                   LogUtils.error(TAG, "warning");
                   ToastTintUtils.warning("Warning Style Toast");
                   break;
               case ButtonValue.BTN_TOAST_TINT_CUSTOM_STYLE:
                   LogUtils.error(TAG, "custom");
                   ToastTintUtils.custom(
                           new TempStyle(), "Custom Style Toast",
                           ResourceUtils.getDrawable(ResourceTable.Media_icon_launcher_round));
                   break;
               default:
                   LogUtils.error(TAG, "default");
                   ToastTintUtils.warning("未处理 " + buttonValue.text + " 事件");
           }
        });
    }

    @Override
    protected int baseLayoutId() {
        return ResourceTable.Layout_base_view_recyclerview;
    }

    @Override
    protected void initView() {

    }

    @Override
    protected void initListener() {
        select_retuen.setClickedListener(component -> {
           LogUtils.error(TAG, "return 点击");
            onBackPressed();
        });
    }

    @Override
    protected void onBackground() {
        super.onBackground();
        bar_Layout.removeAllComponents();
    }

    /*   private void initStrList() {
        buttons.add("Toast Success");
        buttons.add("Toast Error");
        buttons.add("Toast Info");
        buttons.add("Toast Normal");
        buttons.add("Toast Warning");
        buttons.add("Toast Custom Style");
    }*/

    public static List<ButtonValue> getToastButtonValues() {
        List<ButtonValue> lists = new ArrayList<>();
        lists.add(new ButtonValue(ButtonValue.BTN_TOAST_TINT_SUCCESS, "Toast Success"));
        lists.add(new ButtonValue(ButtonValue.BTN_TOAST_TINT_ERROR, "Toast Error"));
        lists.add(new ButtonValue(ButtonValue.BTN_TOAST_TINT_INFO, "Toast Info"));
        lists.add(new ButtonValue(ButtonValue.BTN_TOAST_TINT_NORMAL, "Toast Normal"));
        lists.add(new ButtonValue(ButtonValue.BTN_TOAST_TINT_WARNING, "Toast Warning"));
        lists.add(new ButtonValue(ButtonValue.BTN_TOAST_TINT_CUSTOM_STYLE, "Toast Custom Style"));
        return lists;
    }

    //  自定义实现样式

    private class TempStyle implements ToastTintUtils.Style {

        @Override
        public int getTextColor() {
            return Color.WHITE.getValue();
        }

        @Override
        public float getTextSize() {
            return 50;
        }

        @Override
        public int getBackgroundTintColor() {
            return 0;
        }

        @Override
        public Element getBackground() {
            return null;
        }

        @Override
        public int getMaxLines() {
            return 0;
        }

        @Override
        public int getTintIconColor() {
            return Color.WHITE.getValue();
        }

        @Override
        public boolean isTintIcon() {
            return false;
        }
    }
}
